package org.wyy;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryNTimes;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * curator配置
 *
 * @author mars
 * @date 2024/1/20
 **/
@Configuration
public class CuratorConfig {
    @Resource
    ZkConfig zkConfig;

    @Bean(initMethod = "start")
    public CuratorFramework curatorFramework(){
        /**
         * String connectString, int sessionTimeoutMs, int connectionTimeoutMs, RetryPolicy retryPolicy
         */
        return CuratorFrameworkFactory.newClient(
                zkConfig.getConnectString(),
                zkConfig.getSessionTimeoutMs(),
                zkConfig.getConnectionTimeoutMs(),
                new RetryNTimes(zkConfig.getRetryCount(), zkConfig.getElapsedTimeMs())

        );
    }

}
